import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class PasswordTest {
    public static void main(String[] args) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        
        // 测试的密码哈希值（从数据库中获取的）
        String[] hashes = {
            "$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2",
            "$2a$10$7JB720yubVSNvJF7b0J.LOn5LgT89CJpJTXOu3DEK0TJoXRCb2EGO"
        };
        
        String[] passwords = {"admin123", "123456", "admin", "password"};
        
        System.out.println("=== BCrypt 密码验证测试 ===");
        
        for (int i = 0; i < hashes.length; i++) {
            System.out.println("\n测试哈希 " + (i+1) + ": " + hashes[i]);
            for (String pwd : passwords) {
                boolean matches = encoder.matches(pwd, hashes[i]);
                System.out.println("  密码 '" + pwd + "': " + (matches ? "✓ 匹配" : "✗ 不匹配"));
            }
        }
        
        // 生成 admin123 的新哈希
        System.out.println("\n=== 生成新的 admin123 哈希 ===");
        String newHash = encoder.encode("admin123");
        System.out.println("新哈希: " + newHash);
        System.out.println("验证: " + encoder.matches("admin123", newHash));
    }
} 